<?php

use think\Db;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/26
 * Time: 18:25
 */
class PassportModel extends BaseModel
{
    /**
     * 登录
     */
    public static function login($params = [])
    {
        //验证参数
        if (empty($params) || (!isset($params['username']) && !isset($params['password']))) {
            return [];
        }


        //获取用户
        $user = Db::name('user')->where(['username' => $params['username']])->find();

        //验证设备登录次数
        if ($params['device'] == 'WEB' && self::getIpLoginFailNum() > 5) {
            if (false == self::checkVerify()) {
                return [];
            }
            return [];
        }

        //验证单日登录次数
        if (self::getDayLoginFailNum() > 5) {
            return [];
        }

        //验证密码
        if (md5($params['password']) != $user['password']) {
            return [];
        }


//        //设置session
//        Yaf\Session::getInstance()
//            ->set()
//            ->set()
//            ->set()
//            ->set();

        return $user;
    }

}